var moment = require("moment");

var week = { 1: "一", 2: "二", 3: "三", 4: "四", 5: "五", 6: "六", 7: "日" };


function utilTime(time) {
  const hours = new Date().getHours();
  const date = new Date().getTime() - 3600 * hours * 1000;
  const yesterday = new Date().getTime() - 3600 * 24 * 1000;
  const lastWeek = new Date().getTime() - 3600 * 24 * 1000 * 7;
  if (time > date) {
    return moment(new Date(parseInt(time))).format("HH:mm");
  } else if (time < date && time > yesterday) {
    return "昨天";
  } else if (time < yesterday && time > lastWeek) {
    return "星期" + week[new Date(parseInt(time)).getDay()];
  } else {
    return moment(new Date(parseInt(time))).format("YY/MM/DD");
  }
}

const util = {
  utilTime: utilTime
}

export default util;